//
//  ViewController.h
//  外星球生活圈
//
//  Created by MR.ZHOU on 15/8/12.
//  Copyright (c) 2015年 MR.ZHOU. All rights reserved.
//
#import "DSFunction.h"
#import "MD5.h"
#import "ZFUserInfo.h"

@implementation DSFunction
+ (NSString *)getTimeScamp{
    
    return [NSString stringWithFormat:@"%f",[[NSDate date]timeIntervalSince1970]];
    
}

+ (NSString *)md5StringFromArray:(NSArray *)array{
    
    NSMutableString *item = [NSMutableString string];
    
    [array enumerateObjectsUsingBlock:^(NSString *str , NSUInteger idx, BOOL *stop) {
        
        [item appendString:str];
        
    }];
    
   return  [MD5 MD5Encrypt:item];
    
}

+ (void)saveBoolWithBoolean:(BOOL)flag withKey:(NSString *)key{
    if (key == nil || [key isEqualToString:@""]) {
        return;
    }
    [[NSUserDefaults standardUserDefaults] setBool:flag forKey:key];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

+(void)saveUserInfo:(NSDictionary *)dict{
    
    NSString *str = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
     NSString *file = [str stringByAppendingPathComponent:@"userInfo123"];
   
    [dict writeToFile:file atomically:YES];
    
    
}

+(void)readUserInfo{
      NSString *str = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSString *file = [str stringByAppendingPathComponent:@"userInfo123"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:file];
    
    [ZFUserInfo InfoWithDict:dict];
}
+(void)saveUserimage :(UIImage *)image{
      NSString *str = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSString *file = [str stringByAppendingPathComponent:@"userImage"];

    
    [UIImagePNGRepresentation(image)writeToFile:file  atomically:YES];
    

}
+(UIImage *)readImage{
    NSString *str = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
     NSString *file = [str stringByAppendingPathComponent:@"userImage"];
    
    UIImage *image = [UIImage imageWithContentsOfFile:file ];
    
    return image;
}

+(void)removeData{
     NSString *str = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
     NSString *file = [str stringByAppendingPathComponent:@"userInfo123"];
    //清空沙盒方式1    不行
    
//    NSDictionary *dict = [NSDictionary dictionary];
//    
//    [dict writeToFile:file atomically:YES];
    
      //清空沙盒方式2
    
    NSFileManager *manager = [NSFileManager defaultManager];
    
    [manager removeItemAtPath:file error:nil];
}


+(void)removeCache{
    [ZFUserInfo shareInstance].user_id = @"";
    
    [ZFUserInfo shareInstance].user_name = @"";
    
    [ZFUserInfo shareInstance].isLogin = NO;
}
@end
